<%@ page import="com.Service.UserService" %>
<%@ page import="com.Service.Impl.UserServiceImpl" %>
<%@ page import="com.entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.utils.SqlSessionUtils" %>
<%@ page import="com.Mapper.UserMapper" %>
<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2022/6/14
  Time: 15:31
  To change thiprivate blockquote;
  s template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--加入该标签手动开启el功能--%>
<%@page isELIgnored="false" %>
<html>
<head>
    <title>用户管理</title>
    <script type="text/javascript" src="assets/js/jquery.js"></script>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.5/css/layui.css">
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.5/layui.js">
    <link rel="stylesheet" href="css/UserManage.css">
</head>
<body>
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox mod_default_box">
    </blockquote>
    <table class="layui-table">
        <tr>
            <td>编号</td>
            <td>手机号</td>
            <td>用户名</td>
            <td>密码</td>
            <td>操作</td>
        </tr>
        <c:forEach var="US" items="${US}" varStatus="s">
            <tr>
                <td id="id">${US.id}</td>
                <td id="phone">${US.phone}</td>
                <td id="username">${US.username}</td>
                <td id="password">${US.password}</td>
                <td><a class="layui-btn layui-btn-primary layui-btn-xs open_btn"
                       lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-primary layui-btn-xs  delete_btn" title="移除" lay-event="del">移除</a>
                </td>
            </tr>
        </c:forEach>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>用户管理</legend>
        </fieldset>
    </table>

    <div class="shade_content">
        <div class="col-xs-12 shade_colse">
            <button onclick="javascript:onclick_close();">x</button>
        </div>
        <div class="nav shade_content_div">
            <div class="col-xs-12 shade_title">
                修改用户
            </div>
            <div class="col-xs-12 shade_from">
                <form action="" method="post">
                    <div class="col-xs-12">
                        <span class="span_style">编号</span>
                        <span class="span_style" id="ids"></span>
                    </div>
                    <div class="col-xs-12">
                        <span class="span_style">手机号</span>
                        <input class="input_style" type="" name="phones" id="phones" value=""
                               placeholder="请输入您的手机号"/>
                    </div>
                    <div class="col-xs-12">
                        <span class="span_style">用户名</span>
                        <input class="input_style" type="" name="usernames" id="usernames" value=""
                               placeholder="请输入您的用户名"/>
                    </div>
                    <div class="col-xs-12">
                        <span class="span_style" class="span_sty">密码</span>
                        <input class="input_style" type="" name="passwords" id="passwords" value=""
                               placeholder="请输入您的密码"/>
                    </div>
                    <div class="col-xs-12">
                        <input class="btn_remove" type="button" id="" onclick="javascript:onclick_close();"
                               value="取消"/>
                        <input type="submit" class="sub_set" id="sub_setID" value="提交"/>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            $(document).on("click", ".delete_btn", function () {
                //获取用户姓名
                var username = $(this).parents("tr").find("td:eq(2)").text();
                //获取删除的ID
                var id = $(this).parent().parent().children().eq(0).html();
                alert(id);
                if (confirm("你确定将用户【" + username + "】放入到回收站吗？")) {
                    //根据上面的弹窗判断确认删除发送ajax请求
                    $.get("./UpdateUserStateHS", {
                        id: id
                    }, function (data) {
                        if (data.trim() == "y") {
                            layer.msg("移到回收站成功");
                            $("a[title='移除']").parents("tr").children().eq(0).remove();
                            layer.close(index);
                        } else {
                            layer.msg("移到回收站失败");
                        }
                    });
                }
            })

            $(document).on("click", ".open_btn", function () {
                var id = $(this).parents("tr").find("td:eq(0)").text();
                var phone = $(this).parents("tr").find("td:eq(1)").text();
                var username = $(this).parents("tr").find("td:eq(2)").text();
                var password = $(this).parents("tr").find("td:eq(3)").text();
                $("#ids").text(id);
                $("#phones").val(phone);
                $("#usernames").val(username);
                $("#passwords").val(password);
                $(".shade_content").show();
            })

            $(document).on("click", ".sub_set", function () {
                var id = $("#ids").text();
                var phone = $("#phones").val();
                var username = $("#usernames").val();
                var password = $("#passwords").val();
                $.get("./UpdateUserById", {
                    id: id,
                    phone: phone,
                    username: username,
                    password: password
                }, function (data) {
                    if (data.trim() == "y") {
                        layer.msg("移到回收站成功");
                        $("a[title='移除']").parents("tr").children().eq(0).remove();
                        layer.close(index);
                    } else {
                        layer.msg("移到回收站失败");
                    }
                })
            })
        })

        function onclick_close() {
            var shade_content = $(".shade_content");
            var shade = $(".shade");
            if (confirm("确认关闭么！此操作不可恢复")) {
                shade_content.hide();
                shade.hide();
            }
        }

        $(".shade_content").hide();
    </script>
</form>
</body>
</html>